//
//  SetUserBirthdayView.swift
//  IdleFish
//
//  Created by Ben on 2022/1/3.
//

import SwiftUI

struct SetUserBirthdayView: View {
    
    @EnvironmentObject var userDataVM: UserDataViewModel
    

    
    var body: some View {
        VStack(spacing: 0) {
            Spacer()
            
            HStack {
                Button {
                    userDataVM.showBrithdayPicker.toggle()
                } label: {
                    Text("取消")
                        .foregroundColor(.black)
                }
                
                Spacer()
                
                Button {
                    Task {
                        await userDataVM.updateUserBirthday()
                    }
                } label: {
                    Text("确定")
                        .foregroundColor(.black)
                }
            }
            .frame(height: 40)
            .padding(.horizontal)
            .background(Color.yellow)
            .zIndex(1)
            
            // 性别选择器， userDataVM.selectedGender用来记录当前选择的性别
            
            DatePicker("", selection: $userDataVM.selectedBrithdayDate, in: ...Date(), displayedComponents: .date)
                .labelsHidden()
                .datePickerStyle(.wheel)
            
            .frame(height: 100)
            .frame(maxWidth: .infinity)
            .padding(.bottom, SCREEN_SAFE_INSETS.bottom)
            .background(Color.white)
        }
        .frame(height: SCREEN_HEIGHT)
        .background(Color.black.opacity(0.4))
    }
}

struct SetUserBirthdayView_Previews: PreviewProvider {
    static var previews: some View {
        SetUserBirthdayView()
    }
}
